<template>
	<view class="app-container">
		<view class="header-bar-white search-wrap">
			<view class="input-box">
				<picker @change="bindPickerChange" :value="statusIndex" :range="statusArray">
					<view class="select-box">
						<view class="uni-input text">{{status}}</view>
						<uni-icons type="down" size="16" color="#DCDCDC"></uni-icons>
					</view>
				</picker>
				<input v-model="queryParams.name" placeholder="请输入姓名"/>
				<view class="button-primary button" style="display: flex;" @click="query">
					<uni-icons type="search" size="16" color="#FFFFFF"></uni-icons>查询
				</view>
			</view>
		</view>
		<view v-if="list.length > 0">
			<view class="list">
				<view class="item">
					<view class="title">共 <text class="emphasize">{{total}}</text> 条</view>
				</view>
				<view class="item" v-for="item in list" @click="view(item)">
					<view class="">
						<view class="title">
							<view class="name">{{item.name}}</view>
							<view class="idnumber">{{item.idNumber}}</view>
						</view>
						<view class="label">{{item.regionName?item.regionName:''}}</view>
					</view>
					<view :class="{'uncheck':item.processStatus=='未审核'}">{{item.processStatus}}</view>
				</view>
			</view>
		</view>
		<view class="no-data" v-if="list.length == 0">
			<uni-icons custom-prefix="iconfont" type="icon-no-data" size="32" color="#999999"></uni-icons>
			<text class="text">暂无数据</text>
		</view>
	</view>
</template>

<script>
	import { ApiOrgan } from "@/api/system/index.js";
	import { ApiPerson } from "@/api/subsidy/index.js";
	
	export default {
		data() {
			return {
				user: {},
				status: '已生效',
				statusIndex: 0,
				statusArray: ['已生效', '已注销'],
				queryParams: {
					manageDeptId: null,
					name: null,
					areaCode: undefined,
					streetCode: undefined,
					villageCode: undefined,
					status: '1',
					byDesc: 'id',
					likeColumns: 'name',
					pageNum: 1,
					pageSize: 20,
					// clause: {
					// 	identifyDate: ['null']
					// }
				},
				list: [],
				total: 0,
				pages: 0
			};
		},
		created() {
			this.user = this.$store.getUser();
			this.queryParams.manageDeptId = this.user.manageDeptId;
			//行政区划
			this.getRegion();
		},
		onReachBottom() {
			this.loadMore();
		},
		methods: {
			
			bindPickerChange(event){
				this.status = this.statusArray[event.detail.value];
				if(event.detail.value == 0){
					// this.queryParams.clause.identifyDate = ['null'];
					this.queryParams.status = '1';
				} else {
					// this.queryParams.clause.identifyDate = null;
					this.queryParams.status = '0';
				}
				this.query();
			},
			
			//行政区划
			getRegion(){
				ApiOrgan.getInfo(this.user.deptId).then(res=>{
					let vaild = false;
					let regionCode = res.data.deptCode;
					if(regionCode && regionCode != ''){
						if(regionCode.length == 6){
							//县区
							this.queryParams.areaCode = regionCode;
							vaild = true;
						} else if(regionCode.length == 9){
							//街道乡镇
							this.queryParams.streetCode = regionCode;
							vaild = true;
						} else if(regionCode.length == 12){
							//村居委会
							this.queryParams.villageCode = regionCode;
							vaild = true;
						}
					}
					if(vaild){
						this.getList();
					} else {
						uni.showToast({
							title: '未知行政区域'
						})
					}
				})
			},
			
			query(){
				this.list = [];
				this.queryParams.pageNum = 1;
				this.getList();
			},
			
			getList(){
				ApiPerson.list(this.queryParams).then(res=>{
					this.list.push(...res.data.records);
					this.total = res.data.total;
					this.pages = res.data.pages;
				})
			},
			
			loadMore(){
				if(this.queryParams.pageNum >= this.pages)return;
				this.queryParams.pageNum = this.queryParams.pageNum+1;
				this.getList();
			},
			
			view(row){
				
			}
		}
	};
</script>

<style lang="scss">
	.list{
		width: 100%;
		margin-top: 19upx;
	}
	.list .item{
		width: 100%;
		display: flex;
		justify-content: space-between;
		padding: 30upx;
		box-sizing: border-box;
		background-color: #ffffff;
		margin-top: 1upx;
	}
	.list .item .title{
		display: flex;
		align-items: center;
		font-weight: bold;
	}
	.list .item .title .name{
		width: 100upx;
	}
	.list .item .label{
		color: #666666;
		margin-top: 10upx;
	}
	.list .item .uncheck{
		color: #FF7B00;
	}
	.search-wrap{
		width: 100%;
		display: flex;
		align-items: center;
	}
	.search-wrap .input-box{
		height: 43upx;
		display: flex;
		align-items: center;
		flex-grow: 2;
		border: 1upx solid #dcdcdc;
		border-radius: 30upx;
		padding: 10upx 0upx;
	}
	.select-box{
		display: flex;
		align-items: center;
		padding: 0 15upx;
		border-right: 1upx solid #dcdcdc;
	}
	.select-box .text{
		width:120upx;
	}
	.search-wrap .input-box input{
		flex-grow: 2;
		margin-left: 10upx;
		text-indent: 10upx;
	}
	.search-wrap .button{
		height: 43upx;
		padding: 10upx 20upx;
		border-radius: 30upx;
		margin-left: 10upx;
	}
	.emphasize{
		color: #FF7B00;
	}
</style>
